package com.example.demo.common;

import lombok.Data;

/**
 * @Description TODO
 * @Author Zhangxx
 * @Date 2024/5/10 10:25
 */
@Data
public class Result<T> {
    private T data;
    private Integer code;
    private String msg;

    //操作成功则不需要传入msg属性
    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    //操作失败则需要传入msg属性，说明发生了什么bug
    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

}